package kr.saeildamil.androidStudy_second.actionbar;

import kr.saeildamil.androidStudy_second.R;
import android.content.Context;
import android.view.ActionProvider;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

public class CounterProvider extends ActionProvider {
	Context mContext;
	TextView mCountText;

	public CounterProvider(Context context) {
		super(context);
		this.mContext = context;
	}

	@Override
	public View onCreateActionView() {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		View linear = inflater.inflate(R.layout.counterprovider, null);
		mCountText = (TextView) linear.findViewById(R.id.counterprovider_count);

		linear.findViewById(R.id.counterprovider_btnincrease)
				.setOnClickListener(listener);
		linear.findViewById(R.id.counterprovider_btndecrease)
				.setOnClickListener(listener);
		return linear;
	}

	OnClickListener listener = new OnClickListener() {
		public void onClick(View v) {
			int count = Integer.parseInt(mCountText.getText().toString());
			switch (v.getId()) {
			case R.id.counterprovider_btnincrease:
				mCountText.setText(Integer.toString(count + 1));
				break;
			case R.id.counterprovider_btndecrease:
				mCountText.setText(Integer.toString(count - 1));
				break;
			}

		}
	};

	public boolean onPerformDefaultAction() {
		
		Toast.makeText(mContext,
				"Counter Menu Item Selected -" + "OnPerfomDefaultAction",
				Toast.LENGTH_LONG).show();
		return true;

	};

}
